#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_pushButton_clicked()
{
    // 获取到两个时间框的时间日期
    QDateTime timeold = ui->dateTimeEdit_old->dateTime();
    QDateTime timenew = ui->dateTimeEdit_new->dateTime();

    // 计算两个日期的差值
    int days = timeold.daysTo(timenew);
    int seconds = timeold.secsTo(timenew);

    // 把秒数换算成小时
    int hours = (seconds / 3600) % 24;
//    int days = (seconds / 3600) / 24;

    ui->label->setText(QString("爱你已经持续了") + QString::number(days)
            + QString(" 天零 ") + QString::number(hours) + QString("个小时"));
}
